﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Locator.LcboServices.LcboProductsService.Parsers
{
    class ProductParser
    {
        public string GetProductName(string lcboProductName)
        {
            StringBuilder result = new StringBuilder();
            string[] productNameStrings = lcboProductName.Split();
            // Tres Sabores ¿porqué No? 2007
            for (int i = 0; i < productNameStrings.Length; i++)
            {
                if (!String.IsNullOrEmpty(productNameStrings[i]))
                {
                    bool foundFirstCapital = false;
                    foreach (char productNameChar in productNameStrings[i])
                    {
                        if (!Char.IsLetter(productNameChar))
                            result.Append(productNameChar);
                        else
                        {
                            if (foundFirstCapital)
                                result.Append(productNameChar.ToString(CultureInfo.CurrentCulture).ToLower(CultureInfo.CurrentCulture));
                            else
                            {
                                result.Append(productNameChar);
                                foundFirstCapital = true;
                            }
                        }
                    }
                    //if (productNameStrings[i][0] >= 'A' && productNameStrings[i][0] <= 'Z')
                    //{
                    //    result.Append(productNameStrings[i].Substring(0, 1).ToUpper(CultureInfo.CurrentCulture) + productNameStrings[i].Substring(1).ToLower(CultureInfo.CurrentCulture));
                    //}
                    //else
                    //{

                    //}

                    result.Append(" ");
                }
            }

            //if (currentProduct.Container != null)
            //{
            //    if (currentProduct.Container.NumberOfContainers > 1)
            //    {
            //        result.Append(String.Format("{0}x", currentProduct.Container.NumberOfContainers));
            //    }

            //    result.Append(String.Format("{0} ml", currentProduct.Container.ContainerCapacity));
            //}

            return result.ToString(0, result.Length - 1); // Remove last space
        }
    }
}
